package com.zhou;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * T18
 *
 * @author zhouxianfeng
 * @date 2021-9-3
 */
public class T18 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Point> list = new ArrayList<>(500002);
        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            list.add(new Point(x, y));
        }
        reslove1(list);
    }

    public static void reslove1(List<Point> list) {
        list.sort(new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int i = o1.x - o2.x;
                if (i == 0) {
                    i = o1.y - o2.y;
                }
                return i;
            }
        });
        List<Point> result = new ArrayList<>(500002);
        int maxy = -1;
        for (int i = list.size(); i > 0; i--) {
            Point p1 = list.get(i - 1);
            if (p1.y > maxy) {
                result.add(p1);
                maxy = p1.y;
            }
        }

        for (int i = result.size(); i > 0; i--) {
            Point t = result.get(i - 1);
            System.out.println(t.x + " " + t.y);
        }
    }


    static class Point {
        int x;
        int y;
        //默认为0，当不为0时，标识已经处理过
        int z;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
